package ${package.Controller};

import ${package.Service}.${table.serviceName};
import ${package.Entity}.${entity};
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
<#if restControllerStyle>
import org.springframework.web.bind.annotation.RestController;
<#else>
import org.springframework.stereotype.Controller;
</#if>
<#if superControllerClassPackage??>
import ${superControllerClassPackage};
</#if>
<#if swagger>
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
</#if>
<#if entityLombokModel>
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
</#if>

/**
 * <p>
 * ${table.comment!} 前端控制器
 * </p>
 *
 * @author ${author}
 * @since ${date}
 */
@Validated
<#if entityLombokModel>
@Slf4j
@AllArgsConstructor
</#if>
<#if restControllerStyle>
@RestController
<#else>
@Controller
</#if>
@RequestMapping("<#if package.ModuleName?? && package.ModuleName != "">/${package.ModuleName}</#if>/<#if controllerMappingHyphenStyle>${controllerMappingHyphen}<#else>${table.entityPath}</#if>")
<#if swagger>
@Api(value = "${entity}对象", tags = "${table.comment!}信息管理API")
</#if>
<#if kotlin>
class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
<#if superControllerClass??>
public class ${table.controllerName} extends ${superControllerClass} {
<#else>
public class ${table.controllerName} {
</#if>

<#if entityLombokModel>
    private final ${entity}Service ${table.entityPath}Service;
<#else>
    @Resource
    ${entity}Service ${table.entityPath}Service;
</#if>

    /**
     * 分页查询
     * @param page 分页对象
     * @param ${table.entityPath} ${table.comment!}
     * @return R
     */
<#if swagger>
    @ApiOperation(value = "分页查询", notes = "分页查询")
</#if>
    @GetMapping("/page" )
    public R<Page> getPage(Page<${entity}> page, ${entity} ${table.entityPath}) {
        return R.ok(${table.entityPath}Service.page(page, Wrappers.query(${table.entityPath})));
    }

    /**
     * 通过id查询${table.comment!}
     * @param ${table.entityPath}Id 表id
     * @return R
     */
<#if swagger>
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
</#if>
    @GetMapping("/{${table.entityPath}Id}" )
    public R<${entity}> getById(@PathVariable("${table.entityPath}Id" ) <#list table.fields as field><#if field.keyFlag == true>${field.columnType?lower_case?cap_first}</#if></#list> ${table.entityPath}Id) {
        return R.ok(${table.entityPath}Service.getById(${table.entityPath}Id));
    }

    /**
     * 新增${table.comment!}
     * @param ${table.entityPath} ${table.comment!}
     * @return R
     */
<#if swagger>
    @ApiOperation(value = "新增${table.comment!}", notes = "新增${table.comment!}")
</#if>
    @PostMapping
    public R<Boolean> save(@RequestBody ${entity} ${table.entityPath}) {
        return R.ok(${table.entityPath}Service.save(${table.entityPath}));
    }

    /**
     * 修改${table.comment!}
     * @param ${table.entityPath} ${table.comment!}
     * @return R
     */
<#if swagger>
    @ApiOperation(value = "修改${table.comment!}", notes = "修改${table.comment!}")
</#if>
    @PutMapping
    public R<Boolean> updateById(@RequestBody ${entity} ${table.entityPath}) {
        return R.ok(${table.entityPath}Service.updateById(${table.entityPath}));
    }

    /**
     * 通过id删除${table.comment!}
     * @param ${table.entityPath}Id 表id
     * @return R
     */
<#if swagger>
    @ApiOperation(value = "通过id删除${table.comment!}", notes = "通过id删除${table.comment!}")
</#if>
    @DeleteMapping("/{${table.entityPath}Id}" )
    public R<Boolean> removeById(@PathVariable("${table.entityPath}Id" ) <#list table.fields as field><#if field.keyFlag == true>${field.columnType?lower_case?cap_first}</#if></#list> ${table.entityPath}Id) {
        return R.ok(${table.entityPath}Service.removeById(${table.entityPath}Id));
    }
}
</#if>
